/****************************************************
          File Name:symlink_readlink.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon Dec  8 19:59:54 2014
*****************************************************/

#include "dir.h"

int main(int argc, char *argv[])
{
    int res;
    char cmd[256], buf[256];

    if(argc < 3)
    {
        fprintf(stderr, "%s srcpath dstpath\n", argv[0]);
        exit(1);
    }

    res = symlink(argv[1], argv[2]);
    if(res == -1)
        err("symlink");
    printf("show result:\n");
    snprintf(cmd, 256, "ls -l %s", argv[2]);
    system(cmd);
    sleep(3);

    printf("read link\n");

    res = readlink(argv[2], buf, sizeof(buf));
    if(res == -1)
        err("readlink");
    else
        printf("srcpath: %s (%d)bytes\n", buf, res);

    return 0;
}
